﻿/***********************************************************
Copyright © 2015 Howyoung.
************************************************************
You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty.
************************************************************
您可以对所收受的本程序源代码，无论以何种媒介，复制与发布其完
整的复制物，然而您必须以显著及适当的方式在每一份复制物上发布
适当的著作权标示及无担保声明。
***********************************************************/
using System;
using System.Windows.Forms;

namespace MinecraftSavesBackup
{
    public partial class ViewLog : Form
    {
        public ViewLog()
        {
            InitializeComponent();
        }

        private void ViewLog_Load(object sender, EventArgs e)
        {
            foreach (string log in Properties.Settings.Default.ErrorLog)
            {
                listBox.Items.Add(log);
            }
        }

        private void listBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            textBox.Text = listBox.SelectedItem.ToString();
        }

        private void copyButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox.Text == "")
                {
                    MessageBox.Show("请选择一个日志。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    Clipboard.SetDataObject(textBox.Text);
                    MessageBox.Show("日志已复制到剪贴板。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                HandlingErrors.Record(ex);
            }
        }

        private void cleanButton_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.ErrorLog.Clear();
            Properties.Settings.Default.Save();
            listBox.Items.Clear();
            textBox.Text = null;
        }
    }
}
